#ifndef STOCK_H
#define STOCK_H
#include"subject.h"
#include<random>
#include<iostream>
#include<thread>
using namespace std;

class Stock : public Subject
{
private:
    string m_name;
public:
    Stock(string name = "") : m_name(name)
    {}
    const string & getName() const
    {
        return m_name;
    }
    void notify()
    {
        for(auto & observer : observers)
        {
            observer->update();
        }
    }
    void run()
    {
        uniform_int_distribution<int> i(0,7);
        default_random_engine e;
        for(;;)
        {
            int rate = i(e);
            cout << "本期的股票价格变化率为：" << rate << "%" << endl;
            if(rate>=5)
            {
                cout << "正在为股民发布通告..." << endl;
                notify();
            }
            this_thread::sleep_for(chrono::seconds(2));
        }
    }
};
#endif